package com.yxc.plan.wolf.service.impl;

import com.yxc.plan.wolf.common.ServerResponse;
import com.yxc.plan.wolf.domain.User;
import com.yxc.plan.wolf.domain.po.LoginPO;
import com.yxc.plan.wolf.domain.repository.UserRepository;
import com.yxc.plan.wolf.exception.HttpStatusRuntimeException;
import com.yxc.plan.wolf.service.interfaces.UserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description :
 * @Author : abc@vanke.com
 * @Date : 2018/12/10 3:36 PM
 */

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Override
    public ServerResponse<User> findByPhone(LoginPO loginPO) throws HttpStatusRuntimeException {
        User user = userRepository.findByDeletedAndPhone(false, loginPO.getPhone());
        if (null == user) {
            return ServerResponse.createByErrorMessage("用户不存在");
        }

        if (!StringUtils.equals(loginPO.getPassword(),user.getPassword())) {
            return ServerResponse.createByErrorMessage("用户名或密码不正确");
        }

        return ServerResponse.createBySuccess("登录成功",user);
    }

}
